﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using Toon.Controls;
using System.ComponentModel;

namespace Toon.Dialogs
{
	public partial class SimpleTextWindow : ImprovedChildWindow
	{
		public SimpleTextWindow()
		{
			InitializeComponent();
		}

		public static SimpleTextWindow Show(Control owner, object title, object instructions, Binding textBoxBinding, int? textBoxLines = null)
		{

			var dlg = new SimpleTextWindow();
			dlg.Title = title;
			dlg.Instructions.Content = instructions;
			dlg.BoundTextBox.SetBinding(TextBox.TextProperty, textBoxBinding);
			if (textBoxLines.HasValue)
			{
				dlg.BoundTextBox.Height = textBoxLines.Value * 24;
				dlg.BoundTextBox.AcceptsReturn = textBoxLines.Value > 1;
				dlg.BoundTextBox.KeyUp += (s, e) =>
				{
					if (e.Key == Key.Enter)
						e.Handled = true;
				};
			}

			dlg.Show(owner);

			return dlg;
		}

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

		protected override void OnKeyUp(KeyEventArgs e)
		{
			base.OnKeyUp(e);
			if (!e.Handled && e.Key == Key.Enter)
			{
				e.Handled = true;
				Close();
			}
		}


	}
}

